package cn.wolfcode.wolf2w.controller;

import cn.wolfcode.wolf2w.domain.Banner;
import cn.wolfcode.wolf2w.query.QueryObject;
import cn.wolfcode.wolf2w.service.IBannerService;
import cn.wolfcode.wolf2w.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/banner")
public class BannerController {
	@Autowired
	private IBannerService bannerService;

	@RequestMapping("/list")
	public Object list(Model model, QueryObject qo){
		model.addAttribute("page",bannerService.query(qo));
		return "/banner/list";
	}

	@RequestMapping("/delete")
	@ResponseBody
	public Object delete(String id){
		if(StringUtils.hasLength(id)){
			bannerService.delete(id);
		}
		return  JsonResult.success();
	}

	@RequestMapping("/saveOrUpdate")
	@ResponseBody
	public Object saveOrUpdate(Banner banner){
		if(StringUtils.hasLength(banner.getId())){
			bannerService.update(banner);
		}else {
			bannerService.save(banner);
		}
		return JsonResult.success();
	}

	@RequestMapping("/getAllType")
	@ResponseBody
	public Object getAllType(){
		return  JsonResult.success(bannerService.getAllType());
	}
}
